<?php

namespace app\common\model\xilumarket;

use think\Model;
use function fast\array_get;

class UserMessage extends Model
{
    //消息模块
    const MODULE_TYPE_SYSTEM = 1; //系统通知
    const MODULE_TYPE_INTERACTION = 2; //互动

    //消息类型
    const TYPE_INTERACTION = 0; //互动消息
    const TYPE_NEW_ORDER = 1; //卖家新订单
    const TYPE_CANCEL_ORDER = 2; //买家取消订单，通知卖家
    const TYPE_FINISH_ORDER = 3; //订单完成，通知卖家
    const TYPE_FREIGHT_ORDER = 4; //发货通知买家
    const TYPE_AUTO_CANCEL_ORDER = 5; //订单自动取消通知
    const TYPE_AUTO_FINISH_ORDER = 6; //订单自动完成通知


    protected $name = 'xilumarket_user_message';

    protected $autoWriteTimestamp = 'int';

    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'createtime_text'
    ];

    public function getCreatetimeTextAttr($value,$data){
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
        return is_numeric($value) ? date("Y.m.d H:i", $value) : $value;
    }

    public function setExtraAttr($value, $data) {
        return is_string($value) ? $value : json_encode($value, JSON_UNESCAPED_UNICODE);
    }

    public function getExtraAttr($value, $data) {
        $value = $value ? : array_get($data, 'extra');
        return is_string($value) ? json_decode($value,true) : $value;
    }


}
